
const DefaultStore = {
    categorys: [],
    keyword: "",
    classIndex: 0,
    loading: true,
    loadingText: "loading",
    cartList:[],
    cartItem:{}
}

export const TYPES = {
    LOADPRODUCT:"register/loadproduct",
    CHANGEROUTEMENU:"register/changeroutemenu",
    CHANGELOADING:"register/changeLoading",
    CHANGEPRODUCTCLASSIFY:"register/changeproductclasify",
    ADDCARTLISR:"register/add2cartlist",
    SETEDITCARDITEM:"register/seteditcartitem"
}

export default (store = DefaultStore, action) => {
    switch(action.type){
        case TYPES.LOADPRODUCT:
            return {
                ...store,
                categorys: action.categorys,
                loading: false
            }
        break;
        case TYPES.CHANGEROUTEMENU:
            return {
                ...store,
                registeroute: action.registeroute
            }
        break;
        case TYPES.CHANGELOADING:
            return {
                ...store,
                loadingList:action.loading,
                loadingText: action.loadingText || "loading"
            }
        break;
        case TYPES.CHANGEPRODUCTCLASSIFY:
            return {
                ...store,
                classIndex: action.classIndex
            }
        break;
        case TYPES.ADDCARTLISR:
            return {
                ...store,
                cartList:action.cartList
            }
        break;
        case TYPES.SETEDITCARDITEM:
            return {
                ...store,
                cartItem:action.cartItem
            }
        break;
        default:
            return store
            break;
    }
}